package annotation;

import java.lang.reflect.Method;

/**
 * @author 宋鑫宇
 * @version 1.0
 */
public class AnnotationDemo {
    @MyTest
    public void Test1(){
        System.out.println("Test1");
    }
    public void Test2(){
        System.out.println("Test2");
    }
    @MyTest
    public void Test3(){
        System.out.println("Test3");
    }

    public static void main(String[] args) throws Exception{
        AnnotationDemo a = new AnnotationDemo();
        //1.获取类对象
        Class c = AnnotationDemo.class;
        //2.提取类中的全部方法
        Method[] methods = c.getDeclaredMethods();
        //3.找出有注解的方法
        for (Method method : methods) {
            if (method.isAnnotationPresent(MyTest.class)){
                method.invoke(a);
            }
        }
    }
}
